<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px;">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
          <a-row :gutter="32">
            <a-col :span="6">
              <a-form-item label="收款单号">
                <a-input v-model="queryParam.payCode" placeholder="请输入收款单号"/>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="收款日期">
                <a-date-picker format="YYYY-MM-DD" v-model="queryParam.payDate" placeholder="请输入收款日期" @change="changeDate" :show-today="true"/>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="客户名称">
                <a-input v-model="queryParam.customerName" placeholder="请输入客户名称"/>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="收款账户">
                <a-input v-model="queryParam.payAccount" placeholder="请输入收款账户"/>
              </a-form-item>
            </a-col>
            <a-col>
              <span class="table-page-search-submitButtons" style="float: right;">
                <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
                <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <!-- 新增/修改 -->
    <biz-payment-edit-form v-if="showEditModal" ref="bizPaymentEditForm" :customerIdOptions="customerIdOptions" :payOptions="payOptions" @ok="getList" @close="showEditModal = false" />
    <!-- 明细 -->
    <biz-payment-view-form v-if="showAddModal" ref="bizPaymentViewForm" @ok="getList" @close="showAddModal = false" />
    <a-card :bordered="false" class="table-card">
      <advance-table 
      
      :components="drag(columns)"
      title="收款单" :pagination="{
        current: queryParam.pageNum,
        pageSize: queryParam.pageSize,
        total: total,
        showSizeChanger: true,
        showLessItems: true,
        pageSizeOptions:pageSizeOptions,
        showQuickJumper: true,
        showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
        onChange: changeSize,
        onShowSizeChange: onShowSizeChange
      }" tableKey="base-bizOrder-index-table" @change="handleTableChange" rowKey="id" @refresh="getList"
        :columns="columns" :data-source="dataList" :loading="loading" :format-conditions="true">
        <div class="table-operations" slot="button">
          <!-- <a-button type="primary" @click="handleAdd({})" v-hasPermi="['biz:bizPayment:add']">
            <a-icon type="plus" />新增
          </a-button> -->
          <a-button type="primary" v-hasPermi="['biz:bizCustomerPayable:export']" :loading="downLoading"  @click='exportExcel'>
            <a-icon />导出
          </a-button>
        </div>
        <span slot="operation" slot-scope="{record}" v-if="record.id">
          <a @click="handleDetail(record)" v-hasPermi="['biz:bizPayment:query']">
            明细
          </a>
          <span v-if="record.status == 0" v-hasPermi="['biz:bizPayment:edit']">
            <a-divider type="vertical" />
            <a @click="handleEdit(record)"  >
              修改
            </a>
          </span>
          <a-divider type="vertical" />
          <a  v-hasPermi="['biz:bizPayment:remove']" @click="handleDelete(record)" v-if="record.status == 0">
            删除
          </a>
          <a-divider type="vertical" />
          <a type="primary" @click="audit(record,1)" v-if="record.status == 0" v-hasPermi="['biz:bizPayment:audit']">
            审核
          </a>
          <a type="primary" @click="audit(record,0)" v-if="record.status > 0" v-hasPermi="['biz:bizPayment:audit']">
            反审
          </a>
        </span>
      </advance-table>
    </a-card>
  </div>
</template>
<script>
import { listBizPayment,getInitData,delBizPayment,bizPaymentAudit } from '@/api/biz/bizPayment'
import AdvanceTable from '@/components/pt/table/AdvanceTable'
import BizPaymentEditForm from '@/views/biz/bizpayment/modules/BizPaymentEditForm'
import BizPaymentViewForm from '@/views/biz/bizpayment/modules/BizPaymentViewForm'
import { listAllBizCustomer } from '@/api/biz/bizCustomer'
import tableDragResizeMixin from '@/mixins/tableDragResizeMixin'
import listMixin from '@/mixins/listMixin';
export default {
  name: 'BizPayment',
  components: {
    AdvanceTable,
    BizPaymentEditForm,
    BizPaymentViewForm
  },
  mixins:[tableDragResizeMixin,listMixin],
  data() {
    return {
      showAddModal: false,
      showEditModal:false,
      title:'收款单',
      listFunc:(param)=>listBizPayment(param),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 表格数据
      dataList: [],
      // 供应商列表
      customerIdOptions: [],
      // 付款方式
      payOptions: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 11,
        payCode: undefined,
        customerName: undefined,
        payDate: undefined,
        payAccount: undefined
      },
      
      
      pageSizeOptions: ['11', '21', '31', '101', '201'],
      columns: [
        {
          title: '收款单号',
          dataIndex:'payCode',
          align: 'center'
        },
        {
          title: '对账单号',
          dataIndex:'accountCode',
          align: 'center'
        },
        {
          title: '收款日期',
          dataIndex:'payDate',
          align: 'center'
        },
        {
          title: '客户名称',
          dataIndex:'customerName',
          align: 'center'
        },
        // {
        //   title: '收款账户',
        //   dataIndex:'payAccount',
        //   align: 'center'
        // },
        {
          title: '收款金额',
          dataIndex:'payAmount',
          align: 'center'
        },
        {
          title: '备注',
          dataIndex:'remark',
          align: 'center'
        },
        {
          title: '操作',
          align: 'center',
          scopedSlots: { customRender: 'operation' }
        }
      ]
    }
  },
  created() {
    this.getList()
    getInitData('pay_type').then(response => {
      this.payOptions = response.data.pay_type
    })
    listAllBizCustomer().then(response=>{
      this.customerIdOptions=response.data;
    })
  },
  methods: {
    audit(row, status) {
      var that = this
      that.$confirm({
        title: `确认${status == 0 ? '反' : ''}审核所选中数据?`,
        onOk() {
          return bizPaymentAudit(row.id, status).then((res) => {
            if (res.code === 200) {
              that.$message.success('更新成功', 3)
              that.getList()
              // if(status == 1){
              //   that.form.auditStatus = '1'
              //   that.disabled = false
              //   that.form.version += 1 
              // }else{
              // }
            }
          }).catch(()=>{

          })
        },
        onCancel() { },
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this
      this.$confirm({
        title: '确认删除所选中数据?',
        onOk() {
          return delBizPayment(row.id).then(() => {
            that.onSelectChange([], [])
            that.getList()
            that.$message.success('删除成功', 3)
          })
        },
        onCancel() { },
      })
    },
    /** 查询销售单列表 */
    getList() {
      this.loading = true
      let param = this.getQueryParam()
      listBizPayment(param).then(response => {
        this.dataList = response.data.list
        this.total = response.data.total
        this.loading = false
        this.tableAddTotalRow(this.columns,this.dataList)
      })
    },
    changeDate(dates,dateStr){
      this.queryParam.payDate = dateStr
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        supplierName: undefined
      }
      this.handleQuery()
    },
    handleDetail(row) {
      this.showAddModal = true
      this.$nextTick(() => (
        this.$refs.bizPaymentViewForm.handleView(row)
      ))
    },
    handleEdit(row) {
      this.showEditModal = true
      this.$nextTick(() => (
        this.$refs.bizPaymentEditForm.handleView(row)
      ))
    },
    
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1
      this.queryParam.pageSize = size
      this.getList()
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.ids = this.selectedRows.map(item => item.id)
      this.single = selectedRowKeys.length !== 1
      this.multiple = !selectedRowKeys.length
    },
    handleAdd(record) {
      this.showAddModal = true
      this.$nextTick(() => (
        this.$refs.bizPaymentAddForm.handleAdd(record)
      ))
    },
    handleUpdate(record, ids) {
      this.showAddModal = true
      this.$nextTick(() => (
        this.$refs.bizPaymentAddForm.handleAdd(record)
      ))
    },
    handleTableChange(pagination, filters, sorter) {
      if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') {
        this.queryParam.orderByColumn = 'a.' + sorter.field
        this.queryParam.isAsc = sorter.order
      }
      this.getList()
    }
  }
}
</script>
